package bawei.com.adapter;



import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;

import java.util.List;

import bawei.com.bilibili.R;
import bawei.com.model.bean.AllareasRankBean;


import bawei.com.model.bean.OriginalRankBean;


/**
 * 类描述:
 * 作者：cwm
 * 时间:2017/3/21 11:00
 * 邮箱:18310832074@163.com
 */

public class OrigianRankAdapter extends RecyclerView.Adapter{

    private Context context;
    private List<OriginalRankBean.RankBean.ListBean> listBeen;


    public OrigianRankAdapter(List<OriginalRankBean.RankBean.ListBean> listBeen, Context context) {
        this.listBeen = listBeen;
        this.context = context;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

        return new AllareasRankViewHolder(LayoutInflater.from(context).inflate(R.layout.item_rank_video,parent,false));
    }
    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        if (holder instanceof AllareasRankViewHolder) {
            AllareasRankViewHolder itemViewHolder = (AllareasRankViewHolder) holder;
            OriginalRankBean.RankBean.ListBean listBean = listBeen.get(position);
            itemViewHolder.mVideoTitle.setText(listBean.getTitle());
            itemViewHolder.mVideoPlayNum.setText(String.valueOf(listBean.getPlay()));
            itemViewHolder.mVideoReviewCount.setText(String.valueOf(listBean.getVideo_review()));
            itemViewHolder.mUserName.setText(listBean.getAuthor());
            itemViewHolder.mSortNum.setText(String.valueOf(position + 1));
            setSortNumTextSize(itemViewHolder, position);
            Glide.with(context)
                    .load(listBean.getPic())
                    .centerCrop()
                    .diskCacheStrategy(DiskCacheStrategy.ALL)
                    .placeholder(R.drawable.bili_default_image_tv)
                    .dontAnimate()
                    .into(itemViewHolder.mVideoImg);
        }


    }
    private void setSortNumTextSize(AllareasRankViewHolder itemViewHolder, int position) {

        if (position == 0) {
            itemViewHolder.mSortNum.setTextSize(24);
            itemViewHolder.mSortNum.setTextColor(
                   context.getResources().getColor(R.color.colorPrimary));
        } else if (position == 1) {
            itemViewHolder.mSortNum.setTextSize(22);
            itemViewHolder.mSortNum.setTextColor(
                    context.getResources().getColor(R.color.colorPrimary));
        } else if (position == 2) {
            itemViewHolder.mSortNum.setTextSize(18);
            itemViewHolder.mSortNum.setTextColor(
                    context.getResources().getColor(R.color.colorPrimary));
        } else {
            itemViewHolder.mSortNum.setTextSize(16);
            itemViewHolder.mSortNum.setTextColor(
                    context.getResources().getColor(R.color.black_alpha_30));
        }
    }
    @Override
    public int getItemCount() {
        return listBeen.size();
    }

    class AllareasRankViewHolder extends RecyclerView.ViewHolder{

        ImageView mVideoImg;
        TextView mVideoTitle;
        TextView mVideoPlayNum;
        TextView mVideoReviewCount;
        TextView mSortNum;
        TextView mUserName;

        public AllareasRankViewHolder(View itemView) {
            super(itemView);
            mVideoImg = (ImageView) itemView.findViewById(R.id.item_img);
            mVideoTitle = (TextView) itemView.findViewById(R.id.item_title);
            mVideoPlayNum = (TextView) itemView.findViewById(R.id.item_play);
            mVideoReviewCount = (TextView) itemView.findViewById(R.id.item_review);
            mSortNum = (TextView) itemView.findViewById(R.id.item_sort_num);
            mUserName = (TextView) itemView.findViewById(R.id.item_user_name);
        }
    }

}
